CXX = mpic++  #-fprofile-arcs -ftest-coverage
CPPFLAGS += -g -Wall -DCAFFDRAM_TEST -DKERNEL_UTEST -DNO_MPI -I/usr/include/cppunit -I../.. -I../../../../../ -I../../../../cache
LDFLAGS += -lcppunit

EXECS = bankTest controllerTest 

VPATH = ../.. ../../../../../kernel ../../../../cache/simple-cache

# If the kernel directory already has an object, say clock.o, then the object is
# not built. This may be wrong. So we use different names for kernel objects. This
# way the objects in the kernel directory are not picked up.
KERNEL_OBJS = KERNEL-clock.o KERNEL-component.o KERNEL-manifold.o KERNEL-scheduler.o KERNEL-messenger.o

# Do the same for caffdram
CAFFDRAM_OBJS1 = CAFFDRAM-Bank.o  CAFFDRAM-Dreq.o CAFFDRAM-Dsettings.o
CAFFDRAM_OBJS2 = $(CAFFDRAM_OBJS1) CAFFDRAM-Channel.o  CAFFDRAM-Rank.o
CAFFDRAM_OBJS =  $(CAFFDRAM_OBJS2) CAFFDRAM-Controller.o

SIMPLE_CACHE_OBJS = SIMPLE_CACHE-cache_messages.o

ALL: $(EXECS)

bankTest: bankTest.o $(CAFFDRAM_OBJS1)
	$(CXX) -o$@ $^ $(LDFLAGS)

controllerTest: controllerTest.o $(CAFFDRAM_OBJS) $(KERNEL_OBJS) $(SIMPLE_CACHE_OBJS)
	$(CXX) -o$@ $^ $(LDFLAGS)

KERNEL-%.o: %.cc
	@[ -d dep ] || mkdir dep
	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -MMD -MF dep/$*.d -c $< -o KERNEL-$*.o

CAFFDRAM-%.o: %.cpp
	@[ -d dep ] || mkdir dep
	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -MMD -MF dep/$*.d -c $< -o CAFFDRAM-$*.o

SIMPLE_CACHE-%.o: %.cpp
	@[ -d dep ] || mkdir dep
	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -MMD -MF dep/$*.d -c $< -o SIMPLE_CACHE-$*.o

%.o: %.cc
	@[ -d dep ] || mkdir dep
	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -MMD -MF dep/$*.d -c $< -o $*.o


-include $(wildcard dep/*.d)

.PHONY: clean
clean:
	rm -f $(EXECS) *.o DBG* *.gcda *.gcno *.info
	rm -rf dep
